// pages/finish/finish.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderOpen: false,
    open: false,
    orderId: "",
    time: "",
    feeItemIds: [],
    getTime: [],
    receiveUserId: 0,
    processData: [{
        name: '发单成功',
        // start: '../../icons/lin1.png',
        end: '../../icons/lin1.png',
        icon: '../../icons/l7.png'
      },
      {
        name: '已接单',
        start: '../../icons/lin1.png',
        end: '../../icons/lin1.png',
        icon: '../../icons/l7.png'
      },
      {
        name: '等待双方确认',
        start: '../../icons/lin1.png',
        end: '../../icons/lin1.png',
        icon: '../../icons/l7.png'
      },
      {
        name: '正在赶往途中',
        start: '../../icons/lin1.png',
        end: '../../icons/lin1.png',
        icon: '../../icons/l7.png'
      },
      {
        name: '到达施工地点',
        start: '../../icons/lin1.png',
        end: '../../icons/lin1.png',
        icon: '../../icons/l7.png'
      },
      {
        name: '施工已完成',
        start: '../../icons/lin1.png',
        end: '../../icons/lin1.png',
        icon: '../../icons/l7.png'
      },
      {
        name: '订单已完成',
        start: '../../icons/lin1.png',
        // end: '../../icons/lin2.png',
        icon: '../../icons/l7.png'
      }
    ],

    msgList: [{
      titlePerson: "个人",
      number: "王师傅 164998800022",
      titleAddress: "服务地区",
      address: "南昌县",
      titleRecommend: "服务介绍",
      recommendFirst: "视频监控、门禁",
      recommendSecond: "专注弱电服务三十年，完成数百个大小企业的项目，具有整套的服务流程。",
      titlePromise: "服务承诺",
      promise: [{
          promise: "1.三公里内不收服务费"
        },
        {
          promise: "2.接单1天内处理"
        },
        {
          promise: "3.空跑费50元/次"
        },
        {
          promise: "4.安装后一个月内免检修费"
        }
      ]
    }],
  },
  // 举报
  report: function() {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '是否确认要举报该服务商',
      cancelText: "取消",
      confirmText: "确认",
      success: function(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '../complain/complain?orderId=' + that.data.orderId,
          })
        }
      }

    })

  },
  // 收起界面
  packUp: function(options) {
    console.log(options);
    this.setData({
      open: !this.data.open
    })
  },
  orderInfo: function() {
    this.setData({
      orderOpen: !this.data.orderOpen,

    })
  },
  feeInfo: function() {
    this.setData({
      feeOpen: !this.data.feeOpen,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    console.log(options);
    this.setData({
      orderId: options.userId,
      receiveUserId: options.receiveUserId

    });
    wx.request({
      url: 'https://www.xiaozheng8.com/serviceOrder/sendFindById',
      method: "post",
      data: {
        orderId: that.data.orderId

      },
      success: function(res) {
        console.log(res.data.data);
        for (var i = 0; i < res.data.data.length; i++) {
          if (res.data.data[i].orderId == options.userId) {
            that.setData({
              orderList: [res.data.data[i]],
              time: res.data.data[i].createTime

            })
            console.log()
          }
          // var year = that.data.time.slice(0, 4);
          // var month = that.data.time.slice(5, 7);
          // var day = that.data.time.slice(8, 10);
          // var hour = that.data.time.slice(11, 19);
          // that.setData({
          //   time: year + "年" + month + "月" + day + "日" + hour
          // })

        }
      }
    });
    wx.request({
      url: 'https://www.xiaozheng8.com/receiveUser/findById',
      method: "post",
      data: {
        receiveUserId: that.data.receiveUserId
      },
      success: function(res) {
        console.log(res);
        that.setData({
          msgList: [res.data.data]
        })
      }

    });
  },
  // 拨打电话
  call: function() {
    var that = this;
    console.log(that.data.msgList[0].phone);
    wx.makePhoneCall({
      phoneNumber: that.data.msgList[0].phone,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    wx.request({
      url: 'https://www.xiaozheng8.com/serviceOrder/sendFindById',
      method: "post",
      data: {
        orderId: that.data.orderId
      },
      success: function(res) {
        console.log(res.data.data);
        var num = res.data.data.length;
        console.log(num);

        // for (var i = 0; i < num; i++) {
        //   if (res.data.data[i].orderId == that.data.orderId) {
        that.setData({
          orderList: [res.data.data],
        })
        var fee = res.data.data.feeItemIds;
        that.data.feeItemIds.push(fee.split(" "));
        console.log(that.data.distance);
        that.setData({
          feeItemIds: that.data.feeItemIds,
        })
        // }
        // }
      }
    });
    this.log();
    // for (var i = 0; i < 6; i++) {
    //     that.data.processArr[i].icon = "../../icons/l7.png"
    //   that.data.processArr[i].icon = "../../icons/l7.png"
    //     that.data.processArr[i].icon = "../../icons/l7.png"
    //   that.data.processArrprocessArrprocessArr[i].start = "../../icons/lin1.png"
    //   that.data.processArr[i].end = "../../icons/lin1.png"

    // }
    // that.data.processArr[index].icon = "../../icons/l3.png"
    // that.data.processArr[index].end = "../../icons/lin2.png"
    // that.data.processArr[0].start = "../../icons/lin2.png"

    // this.setData({
    //   processData: processArr
    // })

  },
  log: function() {
    var that = this;
    wx.request({
      url: 'https://www.xiaozheng8.com/serviceOrder/log/v2',
      method: "post",
      data: {
        orderId: that.data.orderId,
        userType: 0
      },
      success: function(res) {
        var time = [];
        console.log(res.data.data);
        for (var i = 0; i < res.data.data.length; i++) {
          if (res.data.data[i].isOk == true && res.data.data[i].status != 8) {
          
              time.push(res.data.data[i])
            
          
          }

        }
        console.log(time);
        that.setData({
          getTime: time
        });
        console.log(that.data.getTime);
        if (that.data.getTime[0].status == 4) {
          that.data.processData[0].time = that.data.getTime[0].time;
          that.data.processData[0].name = that.data.getTime[0].des;
          that.setData({
            processData: that.data.processData
          })
        };
        if (that.data.getTime[1].status == 5) {
          that.data.processData[1].time = that.data.getTime[1].time;
          that.data.processData[1].name = that.data.getTime[1].des;
          that.setData({
            processData: that.data.processData
          });
        }
        if (that.data.getTime.length >= 3) {
          if (that.data.getTime[2].status == 6) {
            that.data.processData[2].time = that.data.getTime[2].time;
            that.data.processData[2].name = that.data.getTime[2].des;
            that.setData({
              processData: that.data.processData
            });
          }
        }
        if (that.data.getTime.length >= 4) {
          if (that.data.getTime[3].status == 7) {
            that.data.processData[3].time = that.data.getTime[3].time;
            that.data.processData[3].name = that.data.getTime[3].des;
            that.setData({
              processData: that.data.processData
            });
          }
        }
        if (that.data.getTime.length >= 5) {
          if (that.data.getTime[4].status == 9) {
            that.data.processData[4].time = that.data.getTime[4].time;
            that.data.processData[4].name = that.data.getTime[4].des;
            that.setData({
              processData: that.data.processData
            });
          }
        }
        if (that.data.getTime.length >= 6) {
          if (that.data.getTime[5].status == 10) {
            that.data.processData[5].time = that.data.getTime[5].time;
            that.data.processData[5].name = that.data.getTime[5].des;
            that.setData({
              processData: that.data.processData
            });
          }
        }
        if (that.data.getTime.length >= 7) {
          if (that.data.getTime[6].status >= 11) {
            that.data.processData[6].name = that.data.getTime[6].des;
            that.data.processData[6].time = that.data.getTime[6].time;
            that.setData({
              processData: that.data.processData
            });
          }
        }




      }

    });
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})